package com.siberiadante.multiscrolldemo.fragment;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.siberiadante.multiscrolldemo.R;
import com.siberiadante.multiscrolldemo.activity.MainActivity;
import com.siberiadante.multiscrolldemo.adapter.MineQuestionAdapter;
import com.siberiadante.multiscrolldemo.fragment.base.LazyFragment;
import com.siberiadante.multiscrolldemo.view.MyWebView;

import butterknife.BindView;

/**
 * @Created SiberiaDante
 * @Describe：
 * @CreateTime: 2017/12/14
 * @UpDateTime:
 * @Email: 2654828081@qq.com
 * @GitHub: https://github.com/SiberiaDante
 */

public class QuestionFragment extends LazyFragment {
    public static final String TAG = QuestionFragment.class.getSimpleName();

    @BindView(R.id.recycler_view)
    MyWebView recyclerView;
    //    @BindView(R.id.refreshLayout)
    //    SmartRefreshLayout refreshLayout;
    private MineQuestionAdapter adapter;

    public static QuestionFragment getInstance() {
        return new QuestionFragment();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_question;
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public void lazyInitView(View view, Bundle savedInstanceState) {
        ((MainActivity) getActivity()).scrollView.setWebView(recyclerView);
        recyclerView.getSettings().setJavaScriptEnabled(true);
        recyclerView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        recyclerView.loadUrl("http://static.fullydar.com/Finance/Finance.html");

        recyclerView.setOnScrollChangeListener(new MyWebView.OnScrollChangeListener() {
            @Override
            public void onPageEnd(int l, int t, int oldl, int oldt) {
                ((MainActivity) getActivity()).scrollView.setNeedScroll(false);
            }

            @Override
            public void onPageTop(int l, int t, int oldl, int oldt) {
                ((MainActivity) getActivity()).scrollView.setNeedScroll(true);
            }

            @Override
            public void onScrollChanged(int l, int t, int oldl, int oldt) {
                ((MainActivity) getActivity()).scrollView.setNeedScroll(false);
            }
        });

        //        final List<MineQuestionBean> data = new ArrayList<>();
        //
        //        final MineQuestionBean questionBean = new MineQuestionBean();
        //        questionBean.setContent("使用NestedScrollView+ViewPager+RecyclerView+SmartRefreshLayout打造酷炫下拉视差效果并解决各种滑动冲突");
        //        data.add(questionBean);
        //
        //        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        //        recyclerView.addItemDecoration(new NormalDecoration(ContextCompat.getColor(mActivity, R.color.mainGrayF8), (int) mActivity.getResources().getDimension(R.dimen.eight)));
        //
        //        adapter = new MineQuestionAdapter(mActivity, new MyWebView.OnScrollChangeListener() {
        //            @Override
        //            public void onPageEnd(int l, int t, int oldl, int oldt) {
        //                ((MainActivity)getActivity()).scrollView.setNeedScroll(false);
        //            }
        //
        //            @Override
        //            public void onPageTop(int l, int t, int oldl, int oldt) {
        //                ((MainActivity)getActivity()).scrollView.setNeedScroll(true);
        //            }
        //
        //            @Override
        //            public void onScrollChanged(int l, int t, int oldl, int oldt) {
        //                ((MainActivity)getActivity()).scrollView.setNeedScroll(false);
        //            }
        //        });
        //
        //        recyclerView.setAdapter(adapter);
        //        adapter.setOnItemClickListener(new RecyclerArrayAdapter.OnItemClickListener() {
        //            @Override
        //            public void onItemClick(int position) {
        //                Toast.makeText(mActivity, "---position---" + position, Toast.LENGTH_SHORT).show();
        //            }
        //        });
        //        adapter.addAll(data);
        //        adapter.setNoMore(R.layout.view_no_more);
        //        adapter.setMore(R.layout.view_more, new RecyclerArrayAdapter.OnMoreListener() {
        //            @Override
        //            public void onMoreShow() {
        //                Log.d(TAG, "----onMoreShow");
        //                adapter.addAll(data);
        //            }
        //
        //            @Override
        //            public void onMoreClick() {
        //
        //            }
        //        });

    }

    @Override
    protected void initData() {

    }
}
